//
//  MyOrderCell.m
//  HuiKaoClient
//
//  Created by 龚 杰 on 13-2-26.
//  Copyright (c) 2013年 龚 杰. All rights reserved.
//

#import "MyOrderCell.h"
#import "asyncimageview.h"

@implementation MyOrderCell
@synthesize priceLabel = m_priceLabel;
@synthesize stateLabel = m_stateLabel;
@synthesize numLabel = m_numLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        m_topview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width,40)];
        [self.contentView addSubview:m_topview];
        
        m_ScrocllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,40,self.frame.size.width-20,70)];
        m_ScrocllView.delegate = self;
        
        m_ScrocllView.pagingEnabled = YES;
        m_ScrocllView.backgroundColor = [UIColor clearColor];
        m_ScrocllView.showsVerticalScrollIndicator = NO;
        m_ScrocllView.showsHorizontalScrollIndicator = NO;
  
        m_footview = [[UIView alloc] initWithFrame:CGRectMake(0, 110, self.frame.size.width,40)];
        [self.contentView addSubview:m_footview];
        UIImageView* upline =  [[UIImageView alloc] initWithFrame:CGRectMake(0,38,self.frame.size.width-20,2)];
        [upline setImage:[UIImage imageNamed:@"line.png"]];
        [self.contentView addSubview:upline];
        [upline release];
        
        UIImageView* underline =  [[UIImageView alloc] initWithFrame:CGRectMake(0,110,self.frame.size.width-20,2)];
        [underline setImage:[UIImage imageNamed:@"line.png"]];
        [self.contentView addSubview:underline];
        [underline release];
        
        m_priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10,200,20)];
        m_priceLabel.backgroundColor = [UIColor clearColor];
        m_priceLabel.font = [UIFont boldSystemFontOfSize:14.0f];
        m_priceLabel.textColor = [UIColor colorWithRed:38/255.0f green:38/255.0f blue:38/255.0f alpha:1.0f];
        [self.contentView  addSubview:m_priceLabel];
        
        m_stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(192,10,200,20)];
        m_stateLabel.backgroundColor = [UIColor clearColor];
        m_stateLabel.font = [UIFont boldSystemFontOfSize:14.0f];
        m_stateLabel.textColor = [UIColor colorWithRed:38/255.0f green:38/255.0f blue:38/255.0f alpha:1.0f];
        [self.contentView addSubview:m_stateLabel];
        
        m_numLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,120,200,20)];
        m_numLabel.backgroundColor = [UIColor clearColor];
        m_numLabel.font = [UIFont boldSystemFontOfSize:14.0f];
        m_numLabel.textColor = [UIColor colorWithRed:38/255.0f green:38/255.0f blue:38/255.0f alpha:1.0f];
        [self.contentView addSubview:m_numLabel];
        
        m_button = [UIButton buttonWithType:UIButtonTypeCustom];
        [m_button retain];
        m_button.frame = CGRectMake(230, 118, 60, 25);
        [m_button setBackgroundImage:[UIImage imageNamed:@"button_yellow_tiny.png"] forState:UIControlStateNormal];
        [m_button setTitle:@"去付款" forState:UIControlStateNormal];
        [m_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        m_button.titleLabel.font = [UIFont systemFontOfSize:12.0f];
        [self.contentView addSubview:m_button];
        
        m_bookname = [[UILabel alloc] initWithFrame:CGRectMake(70,25,200,20)];
        m_bookname.backgroundColor = [UIColor clearColor];
        m_bookname.font = [UIFont boldSystemFontOfSize:14.0f];
        m_bookname.textColor = [UIColor colorWithRed:38/255.0f green:38/255.0f blue:38/255.0f alpha:1.0f];
        [self.contentView addSubview:m_stateLabel];
    }
    return self;
}
- (void)setData:(NSMutableArray*)data pay:(NSString *)_pay
{
    if (data == nil) {
        return;
    }
    NSUInteger w = 0;
    for (int i = 0; i < [data count]; i++) {
        NSDictionary* dic = (NSDictionary*)[data objectAtIndex:i];
        NSString* url = [dic objectForKey:@"image"];
        AsyncImageView* image = [[AsyncImageView alloc] initWithFrame:CGRectMake(5+i*(53+10), 9, 53, 53)];
        image.backgroundColor = [UIColor whiteColor];
        if (url.length) {
            image._imageRequestURL = url;
            image.m_BoolSetImage = YES;
            [image customLoadImageFromURL];
        }
        [m_ScrocllView addSubview:image];
        [image release];
        w = 5+i*(53+10)+73;
    }
    if ([data count] == 1) {
        NSDictionary* dic = (NSDictionary*)[data objectAtIndex:0];
        m_bookname.text = (NSString*)[dic objectForKey:@"name"];
        [m_ScrocllView addSubview:m_bookname];
    }
    
    CGSize newSize = CGSizeMake(w,  70);
    [m_ScrocllView setContentSize:newSize];
    [self.contentView addSubview:m_ScrocllView];
  
    if (_pay.integerValue == 0) {
        [m_button removeFromSuperview];
    }
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)dealloc{
    [m_topview release];
    [m_ScrocllView release];
    [m_footview release];
    [m_priceLabel release];
    [m_stateLabel release];
    [m_numLabel release];
    [m_button release];
    [super dealloc];
}
@end
